package com.sense.kukoo.biz_me.vm

import androidx.lifecycle.MutableLiveData
import com.sense.kukoo.common.file.FileConfig
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.mvvm.vm.BaseViewModel
import com.sense.kukoo.common.repo.Repo
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.lib_logger.LoggerManager


class SettingsViewModel : BaseViewModel() {
    private val TAG: String = javaClass.simpleName

    val data_lastLoginType:MutableLiveData<Int> = MutableLiveData()
    val data_cacheSize:MutableLiveData<String> = MutableLiveData()

    override fun createModel(): BaseMvvmModel? {
        return null
    }

    override fun initData() {
        request {
            //
            val lastLoginType = Repo.loginHistory.lastLoginType()
            data_lastLoginType.postValue(lastLoginType)
            //
            refreshCacheSize()
        }
    }

    fun onCleanCache(){
        request {
            //
            FileConfig.clearAllCache(ApplicationContext.instance())
            //
            refreshCacheSize()
        }

    }

    private fun refreshCacheSize(){
        var fileSize = "0M"
        try {
            fileSize = FileConfig.getTotalCacheSize(ApplicationContext.instance())
        }catch (e:Exception){
            e.printStackTrace()
        }
        data_cacheSize.postValue(fileSize)
    }

}